//package com.tidc.consumer8001.config;
//
//import org.springframework.security.access.AccessDecisionManager;
//import org.springframework.security.access.AccessDeniedException;
//import org.springframework.security.access.ConfigAttribute;
//import org.springframework.security.authentication.AnonymousAuthenticationToken;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.authentication.InsufficientAuthenticationException;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.stereotype.Component;
//
//import java.util.Collection;
//import java.util.Iterator;
//
///**
// * @ClassNmae UrlAccessDecisionManager
// * @Description TODO
// * @Author 冯涛滔
// **/
//@Component
//public class UrlAccessDecisionManager  implements AccessDecisionManager {
//	@Override
//	public void decide(Authentication authentication, Object o, Collection<ConfigAttribute> collection) throws AccessDeniedException, InsufficientAuthenticationException {
//		Iterator<ConfigAttribute> iterator = collection.iterator();
//		while (iterator.hasNext()){
//			ConfigAttribute ca = iterator.next();
//			//当前请求需要的权限
//			String needRole = ca.getAttribute();
//			//這裏是爲了判斷這個請求是不是登錄請求
//			if ("ROLE_LOGIN".equals(needRole)) {
//				if (authentication instanceof AnonymousAuthenticationToken) {
//					throw new BadCredentialsException("未登录");
//				} else
//					return;
//			}
//			//如果不是登錄請求的話
//			//当前用户所具有的权限
//			Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
//			for (GrantedAuthority authority : authorities) {
////                如果有一個角色權限比較通過則一票通過
//				if (authority.getAuthority().equals(needRole)) {
//					return;
//				}
//			}
//		}
//		throw new AccessDeniedException("权限不足!");
//	}
//
//	@Override
//	public boolean supports(ConfigAttribute configAttribute) {
//		return true;
//	}
//
//	@Override
//	public boolean supports(Class<?> aClass) {
//		return true;
//	}
//}
